#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using ZO.SmartCore.Windows.Forms.Design;

#endregion

namespace ZO.SmartCore.Windows.Forms
{
	/// <summary>
	/// Represents color associated with a rectangle.
	/// </summary>
	[TypeConverter(typeof(RectangleColorConverter))]
	[Serializable]
	[StructLayout(LayoutKind.Sequential)]
    [DefaultProperty("All")]
	public class RectangleColor
	{

		#region Constructors


		/// <summary>
		/// Initializes a new instance of the <see cref="RectangleColor"/> class.
		/// </summary>
		/// <param name="all">All.</param>
		public RectangleColor(Color all)
		{
			this._Top = this._Left = this._Right = this._Bottom = all;
			_All = true;
		}

 


		/// <summary>
		/// Initializes a new instance of the <see cref="RectangleColor"/> class.
		/// </summary>
		/// <param name="left">The left.</param>
		/// <param name="top">The top.</param>
		/// <param name="right">The right.</param>
		/// <param name="bottom">The bottom.</param>
		public RectangleColor(Color left, Color top, Color right, Color bottom)
		{
			this._Top = top;
			this._Left = left;
			this._Right = right;
			this._Bottom = bottom;
			this._All = ((this._Top == this._Left) && (this._Top == this._Right)) && (this._Top == this._Bottom);
		}



 

		#endregion

		#region Destructor

		#endregion

		#region Fields


		private bool _All;
		private Color _Top;
		private Color _Left;
		private Color _Right;
		private Color _Bottom;

		#endregion



		#region Properties

		/// <summary>
		/// Gets or sets the left color value.
		/// </summary>
		/// <value>The left.</value>
		[RefreshProperties(RefreshProperties.All)]
		public Color Left
		{
			get
			{
				return _Left;
			}
			set
			{
				if (this._All || (this._Left != value))
				{
					this._All = false;
					this._Left = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the right color value.
		/// </summary>
		[RefreshProperties(RefreshProperties.All)]
		public Color Right
		{
			get
			{
				return _Right;
			}
			set
			{
				if (this._All || (this._Right != value))
				{
					this._All = false;
					this._Right = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the bottom color value.
		/// </summary>
		[RefreshProperties(RefreshProperties.All)]
		public Color Bottom
		{
			get
			{
				return _Bottom;
			}
			set
			{
				if (this._All || (this._Bottom != value))
				{
					this._All = false;
					this._Bottom = value;
				}

			}
		}

		/// <summary>
		/// Gets or sets the top color value.
		/// </summary>
		[RefreshProperties(RefreshProperties.All)]
		public Color Top
		{
			get
			{
				return _Top;
			}
			set
			{
				if (this._All || (this._Top != value))
				{
					this._All = false;
					this._Top = value;
				}

			}
		}

		/// <summary>
		/// Gets or sets the all color value.
		/// </summary>
		[RefreshProperties(RefreshProperties.All)]
		public Color All
		{
			get
			{
				if (!this._All)
				{
					return Color.Transparent;
				}
				return this._Top;

			}
			set
			{

				if (!this._All || (this._Top != value))
				{
					this._All = true;
					this._Top = this._Left = this._Right = this._Bottom = value;


				}
			}
		}
		#endregion

		#region Methods
		/// <summary>
		/// Shoulds the serialize all.
		/// </summary>
		/// <returns></returns>
		internal bool ShouldSerializeAll()
		{
			return this._All;
		}

 

		#endregion
	}
}
